package com.temp.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.temp.dto.SearchUserDTO;
import com.temp.entity.User;
import com.temp.vo.UserDetailVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.math.BigDecimal;
import java.util.List;

@Mapper
public interface UserMapper extends BaseMapper<User> {

    List<UserDetailVO> findAllUserDetail(SearchUserDTO userDTO);

    Integer countAllUserDetail(SearchUserDTO userDTO);

    @Select("SELECT * FROM user u WHERE u.role_id = 3 ORDER BY RAND() LIMIT #{limit}")
    List<User> selectRandomRobots(@Param("limit") int limit);

    @Update("UPDATE user SET balance = balance + #{amount} WHERE id = #{userId}")
    void updateUserBalance(@Param("userId") Long userId, @Param("amount") BigDecimal amount);
}
